Skip to content

feat: Add support for downaloding documents/profile pictures (2fa token needed), expanded homework and general fixes#4

Open
Fefedu973 wants to merge 2 commits intoBlocksHub:mainfrom
Fefedu973:main
Open

feat: Add support for downaloding documents/profile pictures (2fa token needed), expanded homework and general fixes#4
Fefedu973 wants to merge 2 commits intoBlocksHub:mainfrom
Fefedu973:main

Conversation

@Fefedu973
Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and new features, primarily focused on enhancing file download capabilities, supporting 2FA tokens throughout authentication and requests (necessary for the downloàad feature), and expanding type definitions for homework and downloads. The most significant changes are grouped below.

Downloader module enhancements:

  • Major refactor and expansion of the DownloaderModules class to support binary file downloads, cloud file access, and profile photo retrieval, including new helper methods for constructing requests, parsing response headers, and handling authentication headers.
  • Addition of new types for download requests and responses in DownloadRequest.ts, including DownloadRequest, BinaryRequest, BinaryResponse, and related parameter types.
  • The DOWNLOADER_URL function now accepts both string and number file IDs for improved flexibility.

2FA token propagation and handling:

  • The Credential interface now includes an optional token2fa property to store the 2FA token.
  • The authentication flow in AuthModules is updated to extract and store the 2fa-token header when present, ensuring 2FA tokens are preserved and used for subsequent requests. [1] [2]
  • A new getToken2FA method is added to the Client class for convenient retrieval of the current 2FA token.
  • The base Modules class now includes a getAuthHeaders helper that automatically attaches both the main token and 2FA token to all requests if present.

Homework and type definition updates:

  • Several new type exports are added for homework-related entities, including Homework, HomeworkDate, HomeworkEntityType, HomeworkLessonContent, HomeworkSubject, HomeworkTags, and HomeworkUpcoming.
  • The structure of HomeworkUpcoming is updated: HomeworkUpcomingItem is now an interface, and HomeworkUpcoming is a record mapping ISO dates to arrays of these items, improving type safety and clarity. [1] [2]

General improvements and bug fixes:

  • Fixes to module availability checks and selected account handling in the Modules class, making module support validation more robust and accurate. [1] [2]

Type exports for new features:

  • New exports in src/index.ts for all newly introduced types, making them available for consumers of the package.

Introduce download-related types and extend downloader functionality: add src/types/DownloadRequest.ts, export it from index, and implement helpers in Downloader (getDownloadURL/headers/request, getStream refactor, profile photo URL/headers/request and getProfilePhoto). Add clean JSON handling and use configured USER_AGENT/BASE_URL. Add centralized auth header helper in Modules (getAuthHeaders) and improve account/module checks. Update Auth to persist a 2FA token from response headers and removed stray console.log. Add Client.getToken2FA() getter and broaden DOWNLOADER_URL param types in endpoints to accept string|number. Small API surface and behavior changes to support 2FA flows and binary downloads.
Introduce centralized binary fetching in Downloader (executeBinaryRequest) and helper APIs (getBinaryDownloadRequest, getDownloadBinary, getCloudFileRequest, getCloudFile) plus content-disposition parsing (getResponseFileName, decodeContentDispositionValue). Extend BinaryResponse with contentDisposition and fileName. Export CloudFile and several homework-related types from index.ts. Refactor HomeworkUpcoming: add HomeworkUpcomingItem interface and change HomeworkUpcoming to map ISO dates to arrays of items.
@Fefedu973 Fefedu973 changed the title Add 2FA support and enhance download functionality feat: Add support for downaloding documents/profile pictures (2fa token needed), expanded homework and general fixes Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant